package com.neusoft.bizcore.activiti.converter;

import org.activiti.bpmn.model.EndEvent;
import org.activiti.bpmn.model.ExclusiveGateway;
import org.activiti.bpmn.model.FlowElement;
import org.activiti.bpmn.model.SequenceFlow;
import org.activiti.bpmn.model.StartEvent;
import org.activiti.bpmn.model.UserTask;
import org.springframework.stereotype.Component;

import com.neusoft.bizcore.activiti.dto.ProcessNodeDTO;
import com.neusoft.bizcore.activiti.enums.ProcessNodeType;
import com.neusoft.bizcore.web.dto.AbstractConverter;

@Component
public class ProcessNodeConverter extends AbstractConverter<FlowElement, ProcessNodeDTO> {

    @Override
    public FlowElement toModel(final ProcessNodeDTO dto) {
        return null;
    }

    @Override
    public ProcessNodeDTO toDTO(final FlowElement model, final boolean forListView) {

        final ProcessNodeDTO dto = new ProcessNodeDTO();
        dto.setId(model.getId());
        dto.setName(model.getName());

        if (model instanceof UserTask) {

            final UserTask userTaskModel = (UserTask) model;
            dto.setFormKey(userTaskModel.getFormKey());
            dto.setNodeType(ProcessNodeType.userTask);

        } else if (model instanceof StartEvent) {

            final StartEvent startEventModel = (StartEvent) model;

            dto.setNodeType(ProcessNodeType.startEvent);
            dto.setFormKey(startEventModel.getFormKey());

        } else if (model instanceof EndEvent) {

            dto.setNodeType(ProcessNodeType.endEvent);

        } else if (model instanceof SequenceFlow) {

            dto.setNodeType(ProcessNodeType.sequenceFlow);

        } else if (model instanceof ExclusiveGateway) {

            dto.setNodeType(ProcessNodeType.exclusiveGateway);
        }

        return dto;
    }

}
